#!/usr/bin/env python

from PyXSE.Schema import Schema

class DatabaseSchema(Schema):

    """DatabaseSchema is an interface for the Database XML file."""

    schema_label = u'database'
    base_file_name = 'db_schema.xml'
    schema_entry_label = u'table'

    def list_tables(self):
        """Lists the names of tables currently present in the database."""
        return Schema._list_entry_ids(self)

    def create_table(self, table_name):
        """Adds a table to the schema.
        
        table_name: a string representing the name of the new table.

        If the table already exists, an exception is thrown.

        """
        Schema._add(self, [table_name])

    def drop_table(self, table_name):
        """Deletes a table from the schema.

        table_name: a string representing the name of the table to
                    drop.

        If the table does not exist, an exception is thrown.

        """
        Schema._drop(self, table_name)

    def rename_table(self, table_name, new_name):
        """Renames a table.

        table_name: a string representing the name of the table to
                    rename.
        new_name:   a string representing the new name of the table.


        If the table does not exist, or a table named 'new_name'
        already exists, an exception is thrown.

        """
        Schema._rename(self, table_name, new_name)

